package sistemadeproyectos;

import java.awt.Image;
import java.awt.Color;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JColorChooser;

/**
 *
 * @author Angel David
 */
public class FormaVentana extends javax.swing.JDialog {

    public int formaFinal;
    public Color colorLinea;
    public Color colorFondo;
    public Font fuenteFinal;
    public String textoFinal;
    public int alto;
    public int ancho;
    public boolean aceptar = false;
    
    /** Creates new form Forma */
    public FormaVentana(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.jcboTipoForma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Elipse", "Rectangulo"}));
        if(System.getProperty("os.name").substring(0,5).equals("Windo")){
            this.jlblImagen.setIcon(ajustarImagen(System.getProperty("user.dir")+ "\\src\\sistemadeproyectos\\images\\figuras_geometricas.jpg", jlblImagen.getHeight(), jlblImagen.getWidth()));
        }
        else if(System.getProperty("os.name").substring(0,5).equals("Linux")){
            this.jlblImagen.setIcon(ajustarImagen(System.getProperty("user.dir")+ "/src/sistemadeproyectos/images/figuras_geometricas.jpg", jlblImagen.getHeight(), jlblImagen.getWidth()));
        }
        
    }

    private ImageIcon ajustarImagen(String ico, int alto, int ancho) {
        ImageIcon tmpIconAux = new ImageIcon(ico);
        //Escalar Imagen
        ImageIcon tmpIcon = new ImageIcon(tmpIconAux.getImage().getScaledInstance(ancho, alto, Image.SCALE_DEFAULT));
        return tmpIcon;
    }

    public void setForma(int laForma){
        this.jcboTipoForma.setSelectedIndex(laForma-1);
    }
    
    public void setColorFondo(Color unColor){
        this.jlblColorFondo.setBackground(unColor);
    }
    
    public void setColorLinea(Color unColor){
        this.jlblColorLinea.setBackground(unColor);
    }
    
    public void setTexto(String elTexto){
        this.jtxtTexto.setText(elTexto);
    }
    
    public void setFuente(Font laFuente){
        this.jlblEjemplo.setFont(laFuente);
        this.jlblEjemplo.setText(laFuente.getName() + " " + laFuente.getSize());
    }
    
    public void setAlto(String elAlto){
        this.jtxtAlto.setText(elAlto);
    }
    
    public void setAncho(String elAncho){
        this.jtxtAncho.setText(elAncho);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jcboTipoForma = new javax.swing.JComboBox();
        jlblColorLinea = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jbtnEscogerColorLinea = new javax.swing.JButton();
        jtxtTexto = new javax.swing.JTextField();
        jlblEjemplo = new javax.swing.JLabel();
        jbtnEscogerColorFondo = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jlblColorFondo = new javax.swing.JLabel();
        jbtnEscogerFuente = new javax.swing.JButton();
        jbtnAceptar = new javax.swing.JButton();
        jbtnCancelar = new javax.swing.JButton();
        jlblImagen = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtxtAlto = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtxtAncho = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemadeproyectos.SistemadeproyectosApp.class).getContext().getResourceMap(FormaVentana.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setModal(true);
        setName("Form"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jcboTipoForma.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcboTipoForma.setName("jcboTipoForma"); // NOI18N

        jlblColorLinea.setBackground(resourceMap.getColor("jlblColorLinea.background")); // NOI18N
        jlblColorLinea.setText(resourceMap.getString("jlblColorLinea.text")); // NOI18N
        jlblColorLinea.setBorder(javax.swing.BorderFactory.createLineBorder(resourceMap.getColor("jlblColorLinea.border.lineColor"))); // NOI18N
        jlblColorLinea.setName("jlblColorLinea"); // NOI18N
        jlblColorLinea.setOpaque(true);

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jbtnEscogerColorLinea.setText(resourceMap.getString("jbtnEscogerColorLinea.text")); // NOI18N
        jbtnEscogerColorLinea.setName("jbtnEscogerColorLinea"); // NOI18N
        jbtnEscogerColorLinea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnEscogerColorLineaActionPerformed(evt);
            }
        });

        jtxtTexto.setText(resourceMap.getString("jtxtTexto.text")); // NOI18N
        jtxtTexto.setName("jtxtTexto"); // NOI18N

        jlblEjemplo.setText(resourceMap.getString("jlblEjemplo.text")); // NOI18N
        jlblEjemplo.setName("jlblEjemplo"); // NOI18N

        jbtnEscogerColorFondo.setText(resourceMap.getString("jbtnEscogerColorFondo.text")); // NOI18N
        jbtnEscogerColorFondo.setName("jbtnEscogerColorFondo"); // NOI18N
        jbtnEscogerColorFondo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnEscogerColorFondoActionPerformed(evt);
            }
        });

        jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jlblColorFondo.setBackground(resourceMap.getColor("jlblColorFondo.background")); // NOI18N
        jlblColorFondo.setText(resourceMap.getString("jlblColorFondo.text")); // NOI18N
        jlblColorFondo.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jlblColorFondo.setName("jlblColorFondo"); // NOI18N
        jlblColorFondo.setOpaque(true);

        jbtnEscogerFuente.setText(resourceMap.getString("jbtnEscogerFuente.text")); // NOI18N
        jbtnEscogerFuente.setName("jbtnEscogerFuente"); // NOI18N
        jbtnEscogerFuente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnEscogerFuenteActionPerformed(evt);
            }
        });

        jbtnAceptar.setText(resourceMap.getString("jbtnAceptar.text")); // NOI18N
        jbtnAceptar.setName("jbtnAceptar"); // NOI18N
        jbtnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnAceptarActionPerformed(evt);
            }
        });

        jbtnCancelar.setText(resourceMap.getString("jbtnCancelar.text")); // NOI18N
        jbtnCancelar.setToolTipText(resourceMap.getString("jbtnCancelar.toolTipText")); // NOI18N
        jbtnCancelar.setName("jbtnCancelar"); // NOI18N
        jbtnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnCancelarActionPerformed(evt);
            }
        });

        jlblImagen.setText(resourceMap.getString("jlblImagen.text")); // NOI18N
        jlblImagen.setName("jlblImagen"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jtxtAlto.setText(resourceMap.getString("jtxtAlto.text")); // NOI18N
        jtxtAlto.setName("jtxtAlto"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jtxtAncho.setText(resourceMap.getString("jtxtAncho.text")); // NOI18N
        jtxtAncho.setName("jtxtAncho"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlblImagen, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel7))
                                .addGap(21, 21, 21)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jlblEjemplo, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jbtnEscogerFuente))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jcboTipoForma, 0, 181, Short.MAX_VALUE)
                                        .addGap(117, 117, 117))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addComponent(jtxtAlto, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(35, 35, 35)
                                        .addComponent(jLabel8)
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jbtnCancelar)
                                            .addComponent(jtxtAncho, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(65, 65, 65)
                                .addComponent(jbtnAceptar)))
                        .addGap(33, 33, 33))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(23, 23, 23)
                                .addComponent(jlblColorLinea, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                                .addGap(18, 18, 18))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel6))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jtxtTexto, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jlblColorFondo, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                                        .addGap(18, 18, 18)))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jbtnEscogerColorLinea)
                            .addComponent(jbtnEscogerColorFondo))
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addGap(118, 118, 118)
                .addComponent(jLabel1)
                .addContainerGap(131, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(jLabel1)
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jcboTipoForma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jlblColorLinea, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtnEscogerColorLinea))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jlblColorFondo, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtnEscogerColorFondo))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtxtTexto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtnEscogerFuente)
                            .addComponent(jlblEjemplo, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jtxtAlto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jtxtAncho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jbtnAceptar)
                                    .addComponent(jbtnCancelar)))
                            .addComponent(jLabel8)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(jlblImagen, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbtnEscogerColorLineaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnEscogerColorLineaActionPerformed
        // TODO add your handling code here:
        Color newColor = JColorChooser.showDialog(this, "Escoger color de linea", jlblColorLinea.getBackground());
        if (newColor != null) {
            jlblColorLinea.setBackground(newColor);
        }
    }//GEN-LAST:event_jbtnEscogerColorLineaActionPerformed

    private void jbtnEscogerColorFondoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnEscogerColorFondoActionPerformed
        // TODO add your handling code here:
        Color newColor = JColorChooser.showDialog(this, "Escoger color de fondo", jlblColorFondo.getBackground());
        if (newColor != null) {
            jlblColorFondo.setBackground(newColor);
        }
    }//GEN-LAST:event_jbtnEscogerColorFondoActionPerformed

    private void jbtnEscogerFuenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnEscogerFuenteActionPerformed
        // TODO add your handling code here:
        JFrame mainFrame = SistemadeproyectosApp.getApplication().getMainFrame();
        Fuente ventanaFuente = new Fuente(mainFrame, true);
        ventanaFuente.setVisible(true);
        if (ventanaFuente.fuenteEntregada != null){
            jlblEjemplo.setFont(ventanaFuente.fuenteEntregada);
            jlblEjemplo.setText(ventanaFuente.fuenteEntregada.getName() + " " + ventanaFuente.fuenteEntregada.getSize());
        }
    }//GEN-LAST:event_jbtnEscogerFuenteActionPerformed

    private void jbtnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnAceptarActionPerformed
        // TODO add your handling code here:
        //formaFinal = (String)jcboTipoForma.getSelectedItem();ç
        formaFinal = jcboTipoForma.getSelectedIndex()+1;
        colorLinea = jlblColorLinea.getBackground();
        colorFondo = jlblColorFondo.getBackground();
        fuenteFinal = jlblEjemplo.getFont();
        textoFinal = jtxtTexto.getText();
        alto = Integer.parseInt(jtxtAlto.getText());
        ancho = Integer.parseInt(jtxtAncho.getText());
        aceptar = true;
        this.dispose();
    }//GEN-LAST:event_jbtnAceptarActionPerformed

    private void jbtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnCancelarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jbtnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                FormaVentana dialog = new FormaVentana(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JButton jbtnAceptar;
    private javax.swing.JButton jbtnCancelar;
    private javax.swing.JButton jbtnEscogerColorFondo;
    private javax.swing.JButton jbtnEscogerColorLinea;
    private javax.swing.JButton jbtnEscogerFuente;
    private javax.swing.JComboBox jcboTipoForma;
    private javax.swing.JLabel jlblColorFondo;
    private javax.swing.JLabel jlblColorLinea;
    private javax.swing.JLabel jlblEjemplo;
    private javax.swing.JLabel jlblImagen;
    private javax.swing.JTextField jtxtAlto;
    private javax.swing.JTextField jtxtAncho;
    private javax.swing.JTextField jtxtTexto;
    // End of variables declaration//GEN-END:variables
}
